package com.hyts.bmsp.service.account;

import com.hyts.bmsp.model.account.*;
import com.hyts.bmsp.error.ProcessError;
import com.hyts.bmsp.dao.account.UserInfoDAO;
import org.apache.commons.lang.StringUtils;



/**
 * @ClassName: UserInfoServiceImpl
 * @Description: 用户信息业务逻辑接口实现类
 * @author: 李博/Alex
 * @date: 2017-2-16 下午08:05:45
 */
public class UserInfoServiceImpl implements UserInfoService{

	
	/**
	 * @fieldName: userDAO
	 * @fieldType: UserInfoDAO
	 * @Description: 用户信息接口
	 */
	private UserInfoDAO userDAO = new UserInfoDAO();
	
	
	/* (non Javadoc)
	 * @Title: findPwdByUserName
	 * @Description: 根据密码查询用户名：-1：用户名不存在，0：密码错误，1：成功登陆
	 * @param userName
	 * @param password
	 * @return
	 * @see com.alex.jfinal.webapp.service.user.UserInfoService#findPwdByUserName(java.lang.String, java.lang.String)
	 */
	@Override
	public String findPwdByUserName(String userName,String password) {
		
		if(StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)){
			throw new ProcessError("传入的用户名或者密码为空!");
		}
		LoginReturnBO loginBo = userDAO.queryPasswordByUserName(userName);
		if(StringUtils.isEmpty(loginBo.password))
			return "-1";
		if(!password.equals(loginBo.password))
			return "0";
		return loginBo.userId;
	}

	
	/* (non Javadoc)
	 * @Title: loadAccountInfo
	 * @Description: 获取账户信息基本操作，空/或者不空
	 * @param userId
	 * @return
	 * @see com.alex.jfinal.webapp.service.account.UserInfoService#loadAccountInfo(java.lang.String)
	 */
	@Override
	public AccountInfoBean loadAccountInfo(String userId) {
		
		if(StringUtils.isEmpty(userId) || StringUtils.isEmpty(userId)){
			throw new ProcessError("传入的数据获取信息为空!");
		}
		AccountInfoBean bean = userDAO.queryAccountDataByUserId(userId);
		return bean;
	}


	@Override
	public boolean updateAccountInfo(ChangePassWordDTO dto) {
		return userDAO.editAccountPassword(dto);
	}


	/* (non Javadoc)
	 * @Title: loadUserInfo
	 * @Description: TODO
	 * @param userId
	 * @return
	 * @see com.alex.jfinal.webapp.service.account.UserInfoService#loadUserInfo(java.lang.String)
	 */
	@Override
	public UserInfoBean loadUserInfo(String userId) {
		UserInfoBean bean = userDAO.loadUserInfo(userId);
		return bean;
	}


	/* (non Javadoc)
	 * @Title: updateUserInfo
	 * @Description: TODO
	 * @param userId
	 * @param dto
	 * @return
	 * @see com.alex.jfinal.webapp.service.account.UserInfoService#updateUserInfo(java.lang.String, com.alex.jfinal.webapp.bean.account.LoadUserInfoDTO)
	 */
	@Override
	public Boolean updateUserInfo(String userId, LoadUserInfoDTO dto) {
		try {
			return userDAO.editUserInfo(userId, dto);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
}
